package com.springboot.demo.service;

import com.springboot.demo.dao.UserInfoDao;
import com.springboot.demo.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserInfoService {

    @Autowired
    private UserInfoDao userInfoDao;

    public UserInfo findUserInfoByUsername(String username){
        return userInfoDao.findByUsername(username);
    }

    public List<UserInfo> findAll(){
        return userInfoDao.findAll();
    }

    public UserInfo saveUserInfo(UserInfo userInfo){
        return  userInfoDao.save(userInfo);
    }

    public UserInfo findUserInfoById(long id){
        return userInfoDao.findById(id).get();
    }
    public UserInfo updateUserInfo(UserInfo userInfo){
        return userInfoDao.saveAndFlush(userInfo);
    }
    public void deleteUserInfo(long id){
        userInfoDao.deleteById(id);
    }
}
